package com.infovane.action;

import java.util.List;

import com.infovane.base.BaseAction;
import com.infovane.model.PageModel;
import com.infovane.model.TArticle;
import com.infovane.service.ArticleService;
import com.infovane.utils.PagingModule;
import com.infovane.utils.SystemConstant;

public class ArticleAction extends BaseAction{
	
	private ArticleService articleService;
	
	
	public ArticleService getArticleService() {
		return articleService;
	}


	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}


	/**
	 * 分页获取文章数据
	 * */
	public String getArticleList(){
		String strPageNo=httpServletRequest.getParameter("currentPage");
		int currentPage;
		if(strPageNo==null||strPageNo.equals("")){
			currentPage=1;
		}else{
			try{
			currentPage=Integer.parseInt(strPageNo.intern());
			}catch(NumberFormatException e){
				currentPage=1;
			}
		}
		List<TArticle> list=this.articleService.getArticleList(currentPage,SystemConstant.PAGE_SIZE);
		int count=this.articleService.getCount();
		int maxPage=PagingModule.maxPageSize(count);
		PageModel<TArticle> pm=new PageModel<TArticle>(list,maxPage);
		httpServletRequest.setAttribute("pm", pm);
		return SUCCESS;
	}

}
